/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.lcm.metadata.api.i18n;

import io.iec.edp.caf.boot.context.CAFContext;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;
import io.iec.edp.caf.i18n.api.ResourceLocalizer;

import java.text.MessageFormat;

/**
 * 元数据异常类
 *
 * 元数据操作中发生异常后抛出
 *
 * @author liangff
 * @since 0.1.0
 */
public class LcmMetadataDevLog {

    private static final String SU = "pfcommon";
    private static final String RESOURCE_FILE = "metadata_dev_log.properties";
    private final ResourceLocalizer resourceLocalizer;
    private static LcmMetadataDevLog instance;
    public static LcmMetadataDevLog getInstance() {
        if (instance == null) {
            instance = new LcmMetadataDevLog();
        }
        return instance;
    }

    private LcmMetadataDevLog() {
        resourceLocalizer = SpringBeanUtils.getBean(ResourceLocalizer.class);
    }

    public String getString(LogCodes logCodes, String... messageParams) {
        String string = resourceLocalizer.getString(logCodes.name(), RESOURCE_FILE, SU, CAFContext.current.getLanguage());
        return MessageFormat.format(string, messageParams);
    }
}
